package com.sky.controller.user;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.server.DishServer;
import com.sky.vo.DishVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userDishController")
@Slf4j
@RequestMapping("user/dish")
public class DishController {

    @Autowired
    private DishServer dishService;

    @GetMapping("page")
    public Result<PageResult> getPage(DishPageQueryDTO dishPageQueryDTO) {
        log.info("{}", dishPageQueryDTO);
        PageResult pageResult = dishService.pageEmployee(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("{id}")
    public Result<DishVO> getById(@PathVariable Long id) {
        DishVO dishVo = dishService.getById(id);
        return Result.success(dishVo);
    }

    @GetMapping("list")
    public Result<List<DishVO>> getDishList(Long categoryId) {
        log.info("categoryId:{}", categoryId);
        List<DishVO> list = dishService.listByCategoryId(Math.toIntExact(categoryId));
        return Result.success(list);
    }

}
